package com.gis.servlet.find;

import com.gis.bean.Find;
import com.gis.bean.Lost;
import com.gis.dao.FindDao;
import com.gis.util.Constant;
import com.gis.util.ResponseUtil;
import com.gis.util.RestResponse;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author t-zhaoheng
 * @since 2022/5/16
 */
@WebServlet("/find/add")
public class FindAddServlet extends HttpServlet {
  FindDao findDao = FindDao.getInstance();

  /**
   *
   */
  private static final long serialVersionUID = 1L;



  @Override
  protected void doGet(
      HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doPost(req, resp);
  }



  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String username = req.getParameter("username");
    Integer goodsType = Integer.parseInt(req.getParameter("goodsType"));
    String findTime = req.getParameter("findTime");
    Double lng = Double.parseDouble(req.getParameter("lng"));
    Double lat = Double.parseDouble(req.getParameter("lat"));
    String address = req.getParameter("address");
    String description = req.getParameter("description");
    String fileName = req.getParameter("fileName");
    Find find = new Find();
    find.setUsername(username);
    find.setGoodsTypeId(goodsType);
    find.setFindTime(findTime);
    find.setLng(lng);
    find.setLat(lat);
    find.setAddress(address);
    find.setDescription(description);
    find.setFileName(fileName);
    int i = findDao.add(find);
    if (i > 0) {
      ResponseUtil.writeJson(resp, RestResponse.success(Constant.CREATE_SUCCESS));
    } else {
      ResponseUtil.writeJson(resp, RestResponse.fail(Constant.CREATE_FAILED));
    }

  }
}
